package com.example.compreshensiveshop.controller;

import com.example.compreshensiveshop.common.JsonResponse;
import com.example.compreshensiveshop.dto.CartAddDTO;
import com.example.compreshensiveshop.dto.CartUpdateDTO;
import com.example.compreshensiveshop.service.CartService;
import com.example.compreshensiveshop.vo.CartListVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 添加购物车
     *
     * @param cartAddDTO
     */
    @PostMapping("/add")
    public void addCart(@RequestBody CartAddDTO cartAddDTO) {
        cartService.addCart(cartAddDTO);
    }

    /**
     * 查询购物车
     */
    @GetMapping("/queryByCId/{customerId}")
    public PageInfo<CartListVO> queryByCId(Integer pageNum, Integer pageSize, @PathVariable Long customerId) {
        return cartService.queryByCId(customerId, pageNum, pageSize);
    }
    /*@DeleteMapping("/deleteByCIds")
    public void deleteByCIds(@Param("customerIds") List<Long> ids) {
        cartService.deleteByCIds(ids);
    }*/

    /**
     * 删除购物车
     */
    @PutMapping("/deleteByCIds")
    public void deleteByCIds(@RequestParam("ids") List<Long> ids) {
        cartService.deleteByCIds(ids);
    }

    /**
     * 修改购物车
     */
    @PutMapping("/update")
    public void updateCart(@RequestBody CartUpdateDTO cartUpdateDTO) {
        cartService.updateCart(cartUpdateDTO);
    }
}